package com.rc.saas.tenant.component;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获取spring bean
 * Created by sven on 2019/12/10
 */
@Component
public class SpringContextAware implements ApplicationContextAware {
    /**
     * Spring应用上下文
     */
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextAware.context = applicationContext;
    }
    /**
     * 获取Spring应用上下文
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return context;
    }

    /**
     * 获取对象
     * @param name
     * @return
     * @throws BeansException
     */
    public static Object getBean(String name) throws BeansException {
        return context.getBean(name);
    }


}
